//
//  ViewController.swift
//  RXmvvmDemo
//
//  Created by jemi on 2019/12/20.
//  Copyright © 2019 jemi. All rights reserved.
//

import UIKit
import SnapKit
import RxSwift
import RxCocoa

class ViewController: UIViewController {
    
    var textField = UITextField()
    var btn = UIButton()
    var bag = DisposeBag()
    var viewModel = ViewModel()

    override func viewDidLoad() {
        super.viewDidLoad()
        
        loadUI()
        
    }
    
    func loadUI(){
        textField.placeholder = "请输入字符串"
        view.addSubview(textField)
        textField.snp.makeConstraints { (m) in
            m.top.equalTo(90)
            m.leading.equalTo(30)
            m.trailing.equalTo(-30)
            m.height.equalTo(44)
        }
        
        btn.setTitle("按钮", for: .normal)
        btn.setTitleColor(.black, for: .normal)
        view.addSubview(btn)
        btn.snp.makeConstraints { (m) in
            m.leading.trailing.height.equalTo(textField)
            m.top.equalTo(textField.snp_bottom).offset(40)
        }
        
        let input = ViewModel.Input(btn: btn.rx.tap)
        
//    textField.rx.text.orEmpty.asDriver().drive(input.accoutTFText).disposed(by: bag)
        textField.rx.text.orEmpty.bind(to: input.accoutTFText).disposed(by: bag)
        let resu = viewModel.transform(input: input)
        resu.ob.subscribe(onNext: {[weak self] (ob) in
            self?.btn.setTitleColor(.red, for: .normal)
        }).disposed(by: bag)
        
        
       
        Observable.of(2,3,5,7).map { (h) in
            
        }
        
    }

}

